home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Applications… / Banana Jr. ƒ / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  3.3 KB  |  154 lines  |  [TEXT/KAHL]

  1. /*
  2.     main.c
  3.     
  4.     This file contains the main routine, some globals, and that's about it.                            
  5.  
  6.     Created        9/2/92        - Dave Hersey
  7.  
  8.     ----------------------------------------------
  9.  
  10.     2/93    debugged and plopped on GX CD.  - dmh
  11.     9/93    updated to run with the ß2 "GXified" interface files - PLA 
  12.     9/93    Added override for gxPrintingEvent to handle update events.     - dmh
  13.     5/94    PrintingEvent override now only handles appropriate events.     - dmh
  14.     8/94    Universalized.     - dmh
  15. */
  16.  
  17. #include <Resources.h>
  18. #include <Desk.h>
  19. #include <Events.h>
  20. #include <Fonts.h>
  21. #include <Windows.h>
  22. #include <Memory.h>
  23. #include <ToolUtils.h>
  24. #include <Quickdraw.h>
  25.  
  26. #include <GXPrinting.h>
  27. #include <GXEnvironment.h>
  28. #include <GXGraphics.h>
  29. #include <GraphicsLibraries.h>
  30. #include <GXErrors.h>
  31. #include "Banana Jr.h"
  32.  
  33. Boolean        gQuitting;
  34. Str255         gWindowTitle = "\pQuickDraw GX is cool...";
  35. Rect         gWindowQDRect  = {50, 15, 512, 580};
  36. Boolean        gDebugging = false;
  37. Boolean        gGiveMeValidation = false;
  38. long        gGraphicsHeapSize = 500;
  39. short         gAppResRefNum;
  40. long        gSleep = 0;
  41.  
  42. void main()
  43. {        
  44.     CursHandle            theCurs; 
  45.     Handle                menuBar;
  46.     gxGraphicsClient     client;
  47.     OSErr                err;
  48.     WindowPtr            wind;
  49.     char                i;
  50.  
  51.     gAppResRefNum = CurResFile();
  52.     client = GXNewGraphicsClient(nil, gGraphicsHeapSize * 1024L, 0L);
  53.  
  54.     MaxApplZone(); 
  55.     
  56.     for (i = 1; i <= 6; i++)
  57.         MoreMasters(); 
  58.  
  59.     if (gDebugging)
  60.     {
  61.         SetGraphicsLibraryErrors ();
  62.         SetGraphicsLibraryNotices();    
  63.     }
  64.  
  65.     if (gGiveMeValidation) GXSetValidation(gxPublicValidation); 
  66.  
  67.  
  68.     /** Initialize the new graphics and printing environments.  **/
  69.  
  70.     GXEnterGraphics();
  71.     err = GXInitPrinting();
  72.  
  73.     /**   Initialize the other managers, if no errors occured.   **/
  74.      
  75.      if (!err)
  76.      {
  77.          InitGraf(&qd.thePort);
  78.         InitFonts();
  79.         InitWindows();
  80.         InitMenus();
  81.         InitCursor();
  82.  
  83.         theCurs = GetCursor(watchCursor);
  84.         SetCursor(*theCurs);
  85.  
  86.         menuBar = GetNewMBar(rMenuBar);
  87.  
  88.         if (menuBar)
  89.         {
  90.             gQuitting = false;
  91.             SetMenuBar(menuBar);
  92.             DisposHandle(menuBar);
  93.             AddResMenu(GetMHandle(mApple), 'DRVR');
  94.             DrawMenuBar();
  95.  
  96.      // We initialize the CommonColors Library.  This will allow us to set the color of a
  97.      // shape by calling the SetShapeCommonColor function. We will need to call
  98.      // DisposeCommonColors when we leave, to clean up the world.
  99.  
  100.               InitCommonColors();
  101.     
  102.             DoCreateNew();
  103.             SetCursor(&qd.arrow);  
  104.             
  105.             while (!gQuitting)
  106.                 EventLoop();
  107.  
  108.  
  109.     // Leaving.  Close all the windows so we get rid of any data we or GX created.  Then,
  110.     // dispose of the common colors and exit the GX printing and graphics environment.
  111.  
  112.             while (wind = FrontWindow())
  113.                 DoDispose(wind);
  114.  
  115.             DisposeCommonColors();
  116.         }
  117.  
  118.         GXExitPrinting();
  119.     }
  120.     
  121.     GXExitGraphics();
  122.     GXDisposeGraphicsClient(client);
  123. }
  124.  
  125.  
  126. /*------ MyPrintingEventOverride -----------------------------------------------------------------------------*/
  127. // Override for GXPrintingEvent.  It allows us to update our windows
  128. // when the moveable modal printing dialogs are moved.
  129.  
  130. OSErr MyPrintingEventOverride(EventRecord *anEvent, Boolean filterEvent)
  131. {
  132.     OSErr    err = noErr;
  133.  
  134.     // Handle events in whatever way is appropriate.  MyDoEvent is our
  135.     // generic event handler.  We don't pass it events that it shouldn't
  136.     // handle while print dialogs are displayed.
  137.  
  138.     if (!filterEvent)
  139.         switch (anEvent->what)
  140.         {
  141.             case mouseDown:
  142.             case keyDown:
  143.             case autoKey:
  144.                 break;
  145.             
  146.             default:
  147.                 MyDoEvent(anEvent);
  148.         }
  149.  
  150.     return err;
  151. }
  152.  
  153.  
  154.